/*
 * @Author: mayijun
 * @Date: 2022-03-31 11:01:31
 * @LastEditors: mayijun
 * @LastEditTime: 2022-05-05 10:32:32
 */
/* eslint-disable */
import * as path from 'path';
import vuePlugin from '@vitejs/plugin-vue';
import legacyPlugin from '@vitejs/plugin-legacy';
import styleImport from 'vite-plugin-style-import';
import { defineConfig } from 'vite';
import VueJSX from '@vitejs/plugin-vue-jsx';
// https://cn.vitejs.dev/config/
export default ({ command, mode }) => {
  let rollupOptions = {};

  let optimizeDeps = {};

  let esbuild = {};

  return defineConfig({
    base: './', // index.html文件所在位置
    root: './', // js导入的资源路径，src
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
        vue$: 'vue/dist/vue.runtime.esm-bundler.js',
        utils: path.resolve(__dirname, './src/utils')
        // main: path.resolve(__dirname, './src')
      }
    },
    define: {
      'process.env.APP_IS_LOCAL': "'true'"
    },
    server: {
      host: '0.0.0.0',
      proxy: {
        '/api': {
          target: 'http://ibp.digitforce.com/',
          changOrigin: true, //开启代理
          pathRewrite: {
            '^/api': '/api'
          },
          logLevel: 'debug'
        }
      }
    },
    build: {
      target: 'es2015',
      minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
      manifest: false, // 是否产出manifest.json
      sourcemap: false, // 是否产出sourcemap.json
      outDir: 'build', // 产出目录
      rollupOptions
    },
    esbuild,
    optimizeDeps,
    plugins: [
      vuePlugin(),
      VueJSX({}),
      legacyPlugin({
        targets: [
          'Android > 39',
          'Chrome >= 60',
          'Safari >= 10.1',
          'iOS >= 10.3',
          'Firefox >= 54',
          'Edge >= 15'
        ]
      }),
      styleImport({
        libs: [
          {
            libraryName: 'element-plus',
            esModule: true,
            ensureStyleFile: true,
            resolveStyle: (name) => {
              name = name.slice(3);
              return `element-plus/theme-chalk/src/${name}.scss`;
            },
            resolveComponent: (name) => {
              return `element-plus/lib/${name}`;
            }
          }
        ]
      })
    ],
    css: {
      preprocessorOptions: {
        less: {
          // 支持内联 JavaScript
          javascriptEnabled: true
        }
      }
    }
  });
};
